package tetris.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JPanel;

import tetris.board.Board;

/**
 * 
 * The current game status display.
 * 
 * @author Agari NLN (agarin@uw.edu)
 * @version 2.8
 *
 */
public class GameStats extends JPanel
{
  /**
   * This is here to avoid warnings.
   */
  private static final long serialVersionUID = 1L;
  
  /**
   * The score modifier.
   */
  private static final int SCORE_MODIFIER = 10;
  
  /**
   * The default width.
   */
  private static final int DEFAULT_WIDTH = 150;
  
  /**
   * The default height.
   */
  private static final int DEFAULT_HEIGHT = 75;
  
  /**
   * The first line's vertical position.
   */
  private static final int FIRST_LINE = 10;
  
  /**
   * The first line's vertical position.
   */
  private static final int SECOND_LINE = 30;
  
  /**
   * The first line's vertical position.
   */
  private static final int THIRD_LINE = 50;
  
  /**
   * My Tetris board, logic.
   */
  private final Board my_tetris_board;
  
  /**
   * Constructing the current game stats board.
   * @param the_board the Tetris board, logic.
   */
  public GameStats(final Board the_board)
  {
    super();
    my_tetris_board = the_board;
    setBackground(Color.WHITE);
    setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT));
  }
  
  /**
   * Displaying the current game status such as the score and level and the lines cleared.
   * @param the_graphics the actual drawing component.
   */
  public void paintComponent(final Graphics the_graphics)
  {    

    final String lines = "Lines Cleared  " + Board.getLinesCleared();
    final String score = "Score  " + Board.getLinesCleared() * SCORE_MODIFIER;
    final String level = "Level  " + my_tetris_board.getLevel();
    
    super.paintComponent(the_graphics);
    final Graphics2D g2d = (Graphics2D) the_graphics;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setColor(Color.BLACK);
    
    g2d.drawString(score, 0, FIRST_LINE);
    g2d.drawString(lines, 0, SECOND_LINE);
    g2d.drawString(level, 0, THIRD_LINE);
    
    repaint();
  }
}
